<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Spring Boot Thymeleaf + Spring Security</title>

    <div th:replace="/fragments/header :: header-css"/>

</head>
<body>

<div th:replace="/fragments/header :: header"/>

<div class="container">

    <div class="container">

        <!--Show this info message only if posted successfully-->
        <div class="alert alert-info" th:if="${successMessage}" th:utext="${successMessage}"></div>

        <!--New Post Form-->
        <div class="row" style="margin-top:20px">
            <div class="col-xs-12 col-sm-8 col-md-6 col-sm-offset-2 col-md-offset-3">
                <form autocomplete="off" action="#" th:action="@{/newPost}"
                      th:object="${post}" method="post" class="form-horizontal"
                      role="form">

                    <h2 class="text-center">Write new post</h2>

                    <div class="form-group">
                        <label th:if="${#fields.hasErrors('title')}" th:errors="*{title}"
                               class="alert alert-danger"></label>
                        <input type="text" th:field="*{title}" placeholder="Title"
                               class="form-control input-lg"/>
                    </div>

                    <div class="form-group">
                        <label th:if="${#fields.hasErrors('body')}" th:errors="*{body}"
                               class="alert alert-danger"></label>
                        <textarea th:field="*{body}" placeholder="Body"
                                  class="form-control input-lg"/>
                    </div>

                    <input type="hidden" th:field="*{user}"/>
                    <input type="hidden" th:field="*{id}"/>

                    <div class="form-group">
                        <input type="submit" class="btn btn-primary btn-block" value="Save"/>
                    </div>

                </form>
            </div>
        </div>

        <!--Delete Button-->
        <!--Dont show delete button if the post is brand new-->
        <div class="row" th:if="${post.id}">
            <div class="col-md-6 col-md-offset-3">
                <form action="#" th:action="@{'/post/{id}'(id=${post.id})}" th:method="delete"
                      class="form-horizontal">
                    <div class="form-group">
                        <input type="hidden" name="_method" value="delete"/>
                        <button type="submit" class="btn btn-danger btn-block" th:text="Delete">Delete</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

</div>
<!-- /.container -->

<div th:replace="/fragments/footer :: footer"/>

</body>
</html>